import request from '@/utils/axios';
import { auth } from '@/config/env';

export const page = params => {
  return request({
    url: auth + '/tenant/page',
    method: 'post',
    data: params,
  });
};

export const find = params => {
  return request({
    url: auth + '/tenant/find',
    method: 'post',
    data: params,
  });
};

export const findById = id => {
  return request({
    url: auth + '/tenant/' + id,
    method: 'get',
  });
};

export const save = params => {
  return request({
    url: auth + '/tenant',
    method: 'post',
    data: params,
  });
};

export const upt = params => {
  return request({
    url: auth + '/tenant/' + params.id,
    method: 'put',
    data: params,
  });
};

export const del = id => {
  return request({
    url: auth + '/tenant/' + id,
    method: 'delete',
  });
};

export const batchDel = ids => {
  return request({
    url: auth + '/tenant',
    method: 'delete',
    data: ids,
  });
};

// 创建租户
export const create = model => {
  return request({
    url: auth + '/tenant/create',
    method: 'post',
    data: model,
  });
}

// 切换租户
export const toggle = id => {
  return request({
    url: auth + '/tenant/toggle/' + id,
    method: 'get',
  });
}

// 注销租户
export const logoutTenant = id => {
  return request({
    url: auth + '/tenant/logout/' + id,
    method: 'delete',
  });
}

// 变更负责人
export const changeManage = userId => {
  return request({
    url: auth + '/tenant/change/' + userId,
    method: 'put',
  });
}

export const pageTenantFunction = query => {
  return request({
    url: auth + '/tenant/' + query.id + '/function/page',
    method: 'post',
    data: query.data,
  });
};

export const saveTenantFunction = model => {
  return request({
    url: auth + '/tenant/' + model.tenantId + '/function',
    method: 'post',
    data: model.data,
  });
};

export const removeTenantFunction = model => {
  return request({
    url: auth + '/tenant/' + model.id + '/function',
    method: 'delete',
    data: model.data,
  });
};

export const findTenantByUserId = id => {
  return request({
    url: auth + '/tenant/user/' + id,
    method: 'get',
  })
}
